package com.example.vpdemo;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.haibin.calendarview.CalendarLayout;
import com.haibin.calendarview.CalendarView;

public class BottomPopWinDow2 extends PopupWindow implements View.OnClickListener {
    private TextView tvClose;
    private TextView tvTitle;
    private ImageView imgPastMonth;
    private ImageView imgPastYear;
    private TextView tvMonth;
    private ImageView imgNextMonth;
    private ImageView imgNextYear;
    private CalendarLayout calendarLayout;
    private CalendarView calendarView;
    private Context context;
    View mPopView;

    public BottomPopWinDow2(Context context) {
        super(context);
        init(context);
    }


    public BottomPopWinDow2(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public BottomPopWinDow2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        mPopView = LayoutInflater.from(context).inflate(R.layout.layout_popup_calendar2, null);
        setContentView(mPopView);
        setWidth(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的宽
        setHeight(LinearLayout.LayoutParams.MATCH_PARENT);// 设置弹出窗口的高
        // 点击popuwindow外让其消失
        setOutsideTouchable(true);
        setBackgroundDrawable(new ColorDrawable(0x30000000));
        tvClose = (TextView) mPopView.findViewById(R.id.tv_close);
        tvTitle = (TextView) mPopView.findViewById(R.id.tv_title);
        imgPastMonth = (ImageView) mPopView.findViewById(R.id.img_pastMonth);
        imgPastYear = (ImageView) mPopView.findViewById(R.id.img_pastYear);
        tvMonth = (TextView) mPopView.findViewById(R.id.tv_month);
        imgNextMonth = (ImageView) mPopView.findViewById(R.id.img_nextMonth);
        imgNextYear = (ImageView) mPopView.findViewById(R.id.img_nextYear);
        calendarLayout = (CalendarLayout) mPopView.findViewById(R.id.calendarLayout);
        calendarView = (CalendarView) mPopView.findViewById(R.id.calendarView);

        tvClose.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        if (mPopView != null) {
            dismiss();
        }
    }

    public void show() {
        showAtLocation(((Activity) context).getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
    }
}
